#include<stdio.h>
#include<string.h>
void delete_string(char str[],int position,int length)
{
	char string[100]={0};
	//如果字符串为空
	if(!strlen(str))
	{
		printf("字符串长度为0无法删除！\n");
		return ;
	}
	else
	{
		strncpy(string,str,position-1);//将要删除的前position个字符复制到string数组中
		string[position]='\0';
		strcat(string,(str+position+length-1));
		memset(str,0,strlen(str));
		strcpy(str,string);
	}
	
	
}
char delete_string1(char str[],int position,int length)
{
	int i;
	for(i=position+length-1;str[i]!='\0';i++,position++)//i的初值为指定删除部分后的第一个字符
	{
		str[position-1]=str[i];//将删除部分后的字符依次覆盖在要删除的部分
	}
	str[position-1]='\0';	
	return str;
}
int main()
{
	char str[100];
	int position;
	int length;
	printf("Please input string:\n");
	gets(str);
	
	printf("Please input delete position:\n");
	scanf("%d",&position);
	
	printf("Please input delete length:\n");
	scanf("%d",&length);
	delete_string( str, position, length);

	printf("方法1：\n");
	puts(str);

	printf("方法2：\n");
	delete_string1( str, position, length);
	puts(str);
	
	return 0;
}
